package com.itheima.controller;

import com.itheima.common.constant.MessageConstant;
import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.common.entity.Result;
import com.itheima.pojo.CheckGroup;
import com.itheima.pojo.CheckItem;
import com.itheima.pojo.CheckgroupItem;
import com.itheima.service.CheckgroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RequestMapping("/checkgroup")
@RestController
@Api(tags = "检查组相关功能")
public class CheckgroupController {
    @Autowired
    private CheckgroupService checkgroupService;

    @ApiOperation("新增检查组")
    @PostMapping("/add")
    public Result groupAdd(@RequestBody CheckGroup checkGroup, @RequestParam List<Integer> checkitemIds) {
        checkgroupService.addChechGroup(checkGroup, checkitemIds);
        System.out.println(checkitemIds);
        return new Result(true, MessageConstant.ADD_CHECKITEM_SUCCESS);
    }


    @ApiOperation("检查组分页查询")
    @PostMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean) {
        PageResult pageResult=checkgroupService.pageQuery(queryPageBean);
        return pageResult;
    }

    @ApiOperation("检查组编辑功能")
    @PostMapping("/edit")
    public Result editGroup(@RequestBody CheckGroup checkGroup,@RequestParam List<Integer> checkitemIds){
        checkgroupService.edit(checkGroup,checkitemIds);
        return new Result(true,MessageConstant.EDIT_CHECKGROUP_SUCCESS);
    }

    @ApiOperation("根据检查组id查询检查组")
    @GetMapping("/findById")
    public Result findById(Integer id){
        CheckGroup checkGroup=checkgroupService.getByid(id);
        return new Result(true,MessageConstant.QUERY_CHECKGROUP_SUCCESS,checkGroup);
    }

    @ApiOperation("查询所有检查组")
    @GetMapping("findAll")
    public Result findAll(){
        List<CheckGroup> list=checkgroupService.findAllCheckGroup();
        return new Result(true,MessageConstant.QUERY_CHECKITEM_SUCCESS,list);
    }
}
